home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / x11-common.preinst < prev    next >
Encoding:
Text File  |  2011-12-16  |  21.5 KB  |  668 lines

  1. #!/bin/sh
  2. # Debian x11-common package pre-installation script
  3. # Copyright 1998--2001, 2003 Branden Robinson.
  4. # Licensed under the GNU General Public License, version 2.  See the file
  5. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  6. # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  7.  
  8. set -e
  9.  
  10. . /usr/share/debconf/confmodule
  11.  
  12. THIS_PACKAGE=x11-common
  13. THIS_SCRIPT=preinst
  14. CONFIG_DIR=/etc/X11
  15. XWRAPPER_CONFIG="$CONFIG_DIR/Xwrapper.config"
  16. CONFIG_AUX_DIR=/var/lib/x11
  17. XWRAPPER_CONFIG_ROSTER_BASE="${XWRAPPER_CONFIG##*/}.roster"
  18. XWRAPPER_CONFIG_ROSTER="$CONFIG_AUX_DIR/$XWRAPPER_CONFIG_ROSTER_BASE"
  19. XWRAPPER_CONFIG_CHECKSUM_BASE="${XWRAPPER_CONFIG##*/}.md5sum"
  20. XWRAPPER_CONFIG_CHECKSUM="$CONFIG_AUX_DIR/$XWRAPPER_CONFIG_CHECKSUM_BASE"
  21.  
  22. # This is the X Strike Force shell library for X Window System package
  23. # maintainer scripts.  It serves to define shell functions commonly used by
  24. # such packages, and performs some error checking necessary for proper operation
  25. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  26. # invoke the functions defined here to accomplish package installation and
  27. # removal tasks.
  28.  
  29. # If you are reading this within a Debian package maintainer script (e.g.,
  30. # /var/lib/dpkg/info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  31. # skip past this library by scanning forward in this file to the string
  32. # "GOBSTOPPER".
  33.  
  34. SOURCE_VERSION=1:7.5+8+squeeze1
  35. OFFICIAL_BUILD=
  36.  
  37. # Use special abnormal exit codes so that problems with this library are more
  38. # easily tracked down.
  39. SHELL_LIB_INTERNAL_ERROR=86
  40. SHELL_LIB_THROWN_ERROR=74
  41. SHELL_LIB_USAGE_ERROR=99
  42.  
  43. # old -> new variable names
  44. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  45.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  46. fi
  47. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  48.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  49. fi
  50.  
  51. # initial sanity checks
  52. if [ -z "$THIS_PACKAGE" ]; then
  53.   cat >&2 <<EOF
  54. Error: package maintainer script attempted to use shell library without
  55. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  56. version, and the text of this error message to the Debian Bug Tracking System.
  57. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  58. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  59. "doc-debian" package, or install the "reportbug" package and use the command of
  60. the same name to file a report against version $SOURCE_VERSION of this package.
  61. EOF
  62.   exit $SHELL_LIB_USAGE_ERROR
  63. fi
  64.  
  65. if [ -z "$THIS_SCRIPT" ]; then
  66.   cat >&2 <<EOF
  67. Error: package maintainer script attempted to use shell library without
  68. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  69. version, and the text of this error message to the Debian Bug Tracking System.
  70. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  71. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  72. "doc-debian" package, or install the "reportbug" package and use the command of
  73. the same name to file a report against version $SOURCE_VERSION of the
  74. "$THIS_PACKAGE" package.
  75. EOF
  76.   exit $SHELL_LIB_USAGE_ERROR
  77. fi
  78.  
  79. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  80.   RECONFIGURE="true"
  81. else
  82.   RECONFIGURE=
  83. fi
  84.  
  85. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  86.   FIRSTINST="yes"
  87. fi
  88.  
  89. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  90.   UPGRADE="yes"
  91. fi
  92.  
  93. trap "message;\
  94.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  95.       message;\
  96.       exit 1" HUP INT QUIT TERM
  97.  
  98. reject_nondigits () {
  99.   # syntax: reject_nondigits [ operand ... ]
  100.   #
  101.   # scan operands (typically shell variables whose values cannot be trusted) for
  102.   # characters other than decimal digits and barf if any are found
  103.   while [ -n "$1" ]; do
  104.     # does the operand contain anything but digits?
  105.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  106.       # can't use die(), because it wraps message() which wraps this function
  107.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  108.            "possibly malicious garbage \"$1\"" >&2
  109.       exit $SHELL_LIB_THROWN_ERROR
  110.     fi
  111.     shift
  112.   done
  113. }
  114.  
  115. reject_unlikely_path_chars () {
  116.   # syntax: reject_unlikely_path_chars [ operand ... ]
  117.   #
  118.   # scan operands (typically shell variables whose values cannot be trusted) for
  119.   # characters unlikely to be seen in a path and which the shell might
  120.   # interpret and barf if any are found
  121.   while [ -n "$1" ]; do
  122.     # does the operand contain any funny characters?
  123.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  124.       # can't use die(), because I want to avoid forward references
  125.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  126.            "encountered possibly malicious garbage \"$1\"" >&2
  127.       exit $SHELL_LIB_THROWN_ERROR
  128.     fi
  129.     shift
  130.   done
  131. }
  132.  
  133. # Query the terminal to establish a default number of columns to use for
  134. # displaying messages to the user.  This is used only as a fallback in the
  135. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  136. # the script is running, and this cannot, only being calculated once.)
  137. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  138. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  139.   DEFCOLUMNS=80
  140. fi
  141.  
  142. message () {
  143.   # pretty-print messages of arbitrary length
  144.   reject_nondigits "$COLUMNS"
  145.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  146. }
  147.  
  148. observe () {
  149.   # syntax: observe message ...
  150.   #
  151.   # issue observational message suitable for logging someday when support for
  152.   # it exists in dpkg
  153.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  154.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  155.   fi
  156. }
  157.  
  158. warn () {
  159.   # syntax: warn message ...
  160.   #
  161.   # issue warning message suitable for logging someday when support for
  162.   # it exists in dpkg; also send to standard error
  163.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  164. }
  165.  
  166. die () {
  167.   # syntax: die message ...
  168.   #
  169.   # exit script with error message
  170.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  171.   exit $SHELL_LIB_THROWN_ERROR
  172. }
  173.  
  174. internal_error () {
  175.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  176.   message "internal error: $*"
  177.   if [ -n "$OFFICIAL_BUILD" ]; then
  178.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  179.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  180.             "Tracking System.  Include all messages above that mention the" \
  181.             "$THIS_PACKAGE package.  Visit " \
  182.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  183.             "instructions, read the file" \
  184.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  185.             "package, or install the reportbug package and use the command of" \
  186.             "the same name to file a report."
  187.   fi
  188.   exit $SHELL_LIB_INTERNAL_ERROR
  189. }
  190.  
  191. usage_error () {
  192.   message "usage error: $*"
  193.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  194.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  195.           "Tracking System.  Include all messages above that mention the" \
  196.           "$THIS_PACKAGE package.  Visit " \
  197.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  198.           "instructions, read the file" \
  199.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  200.           "package, or install the reportbug package and use the command of" \
  201.           "the same name to file a report."
  202.   exit $SHELL_LIB_USAGE_ERROR
  203. }
  204.  
  205. font_update () {
  206.   # run $UPDATECMDS in $FONTDIRS
  207.  
  208.   local dir cmd shortcmd x_font_dir_prefix
  209.  
  210.   x_font_dir_prefix="/usr/share/fonts/X11"
  211.  
  212.   if [ -z "$UPDATECMDS" ]; then
  213.     usage_error "font_update() called but \$UPDATECMDS not set"
  214.   fi
  215.   if [ -z "$FONTDIRS" ]; then
  216.     usage_error "font_update() called but \$FONTDIRS not set"
  217.   fi
  218.  
  219.   reject_unlikely_path_chars "$UPDATECMDS"
  220.   reject_unlikely_path_chars "$FONTDIRS"
  221.  
  222.   for dir in $FONTDIRS; do
  223.     if [ -d "$x_font_dir_prefix/$dir" ]; then
  224.       for cmd in $UPDATECMDS; do
  225.         if which "$cmd" > /dev/null 2>&1; then
  226.           shortcmd=${cmd##*/}
  227.           observe "running $shortcmd in $dir font directory"
  228.       cmd_opts=
  229.           if [ "$shortcmd" = "update-fonts-alias" ]; then
  230.             cmd_opts=--x11r7-layout
  231.           fi
  232.           if [ "$shortcmd" = "update-fonts-dir" ]; then
  233.             cmd_opts=--x11r7-layout
  234.           fi
  235.           if [ "$shortcmd" = "update-fonts-scale" ]; then
  236.             cmd_opts=--x11r7-layout
  237.           fi
  238.           $cmd $cmd_opts $dir || warn "$cmd $cmd_opts $dir" \
  239.                               "failed; font directory data may not" \
  240.                               "be up to date"
  241.         else
  242.           warn "$cmd not found; not updating corresponding $dir font" \
  243.                "directory data"
  244.         fi
  245.       done
  246.     else
  247.       warn "$dir is not a directory; not updating font directory data"
  248.     fi
  249.   done
  250. }
  251.  
  252. remove_conffile_prepare () {
  253.   # syntax: remove_conffile_prepare filename official_md5sum ...
  254.   #
  255.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  256.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  257.   # operands provided, then prepare the conffile for removal from the system.
  258.   # We defer actual deletion until the package is configured so that we can
  259.   # roll this operation back if package installation fails.
  260.   #
  261.   # Call this function from a preinst script in the event $1 is "upgrade" or
  262.   # "install" and verify $2 to ensure the package is being upgraded from a
  263.   # version (or installed over a version removed-but-not-purged) prior to the
  264.   # one in which the conffile was obsoleted.
  265.  
  266.   local conffile current_checksum
  267.  
  268.   # validate arguments
  269.   if [ $# -lt 2 ]; then
  270.     usage_error "remove_conffile_prepare() called with wrong number of" \
  271.                 "arguments; expected at least 2, got $#"
  272.     exit $SHELL_LIB_USAGE_ERROR
  273.   fi
  274.  
  275.   conffile="$1"
  276.   shift
  277.  
  278.   # does the conffile even exist?
  279.   if [ -e "$conffile" ]; then
  280.     # calculate its checksum
  281.     current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//')
  282.     # compare it to each supplied checksum
  283.     while [ -n "$1" ]; do
  284.       if [ "$current_checksum" = "$1" ]; then
  285.         # we found a match; move the confffile and stop looking
  286.         observe "preparing obsolete conffile $conffile for removal"
  287.         mv "$conffile" "$conffile.$THIS_PACKAGE-tmp"
  288.         break
  289.       fi
  290.       shift
  291.     done
  292.   fi
  293. }
  294.  
  295. remove_conffile_lookup () {
  296.   # syntax: remove_conffile_lookup package filename
  297.   #
  298.   # Lookup the md5sum of a conffile in dpkg's database, and prepare for removal
  299.   # if it matches the actual file's md5sum.
  300.   #
  301.   # Call this function when you would call remove_conffile_prepare but only
  302.   # want to check against dpkg's status database instead of known checksums.
  303.  
  304.   local package conffile old_md5sum
  305.  
  306.   # validate arguments
  307.   if [ $# -ne 2 ]; then
  308.     usage_error "remove_conffile_lookup() called with wrong number of" \
  309.                 "arguments; expected 1, got $#"
  310.     exit $SHELL_LIB_USAGE_ERROR
  311.   fi
  312.  
  313.   package="$1"
  314.   conffile="$2"
  315.  
  316.   if ! [ -e "$conffile" ]; then
  317.     return
  318.   fi
  319.   old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$package" | \
  320.     awk '{ if (match($0, "^ '"$conffile"' ")) print $2}')"
  321.   if [ -n "$old_md5sum" ]; then
  322.     remove_conffile_prepare "$conffile" "$old_md5sum"
  323.   fi
  324. }
  325.  
  326. remove_conffile_commit () {
  327.   # syntax: remove_conffile_commit filename
  328.   #
  329.   # Complete the removal of a conffile "filename" that has become obsolete.
  330.   #
  331.   # Call this function from a postinst script after having used
  332.   # remove_conffile_prepare() in the preinst.
  333.  
  334.   local conffile
  335.  
  336.   # validate arguments
  337.   if [ $# -ne 1 ]; then
  338.     usage_error "remove_conffile_commit() called with wrong number of" \
  339.                 "arguments; expected 1, got $#"
  340.     exit $SHELL_LIB_USAGE_ERROR
  341.   fi
  342.  
  343.   conffile="$1"
  344.  
  345.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  346.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  347.     observe "committing removal of obsolete conffile $conffile"
  348.     rm "$conffile.$THIS_PACKAGE-tmp"
  349.   fi
  350. }
  351.  
  352. remove_conffile_rollback () {
  353.   # syntax: remove_conffile_rollback filename
  354.   #
  355.   # Roll back the removal of a conffile "filename".
  356.   #
  357.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  358.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  359.   # preinst.
  360.  
  361.   local conffile
  362.  
  363.   # validate arguments
  364.   if [ $# -ne 1 ]; then
  365.     usage_error "remove_conffile_rollback() called with wrong number of" \
  366.                 "arguments; expected 1, got $#"
  367.     exit $SHELL_LIB_USAGE_ERROR
  368.   fi
  369.  
  370.   conffile="$1"
  371.  
  372.   # if the temporary file created by remove_conffile_prepare() exists, move it
  373.   # back
  374.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  375.     observe "rolling back removal of obsolete conffile $conffile"
  376.     mv "$conffile.$THIS_PACKAGE-tmp" "$conffile"
  377.   fi
  378. }
  379.  
  380. replace_conffile_with_symlink_prepare () {
  381.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  382.   # official_md5sum ...
  383.   #
  384.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  385.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  386.   # operands provided, then prepare the conffile for removal from the system.
  387.   # We defer actual deletion until the package is configured so that we can
  388.   # roll this operation back if package installation fails. Otherwise copy it
  389.   # to newfilename and let dpkg handle it through conffiles mechanism.
  390.   #
  391.   # Call this function from a preinst script in the event $1 is "upgrade" or
  392.   # "install" and verify $2 to ensure the package is being upgraded from a
  393.   # version (or installed over a version removed-but-not-purged) prior to the
  394.   # one in which the conffile was obsoleted.
  395.  
  396.   local conffile current_checksum
  397.  
  398.   # validate arguments
  399.   if [ $# -lt 3 ]; then
  400.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  401.                 " number of arguments; expected at least 3, got $#"
  402.     exit $SHELL_LIB_USAGE_ERROR
  403.   fi
  404.  
  405.   oldconffile="$1"
  406.   shift
  407.   newconffile="$1"
  408.   shift
  409.  
  410.   remove_conffile_prepare "$_oldconffile" "$@"
  411.   # If $oldconffile still exists, then md5sums didn't match.
  412.   # Copy it to new one.
  413.   if [ -f "$oldconffile" ]; then
  414.     cp "$oldconffile" "$newconffile"
  415.   fi
  416.  
  417. }
  418.  
  419. replace_conffile_with_symlink_commit () {
  420.   # syntax: replace_conffile_with_symlink_commit oldfilename
  421.   #
  422.   # Complete the removal of a conffile "oldfilename" that has been
  423.   # replaced by a symlink.
  424.   #
  425.   # Call this function from a postinst script after having used
  426.   # replace_conffile_with_symlink_prepare() in the preinst.
  427.  
  428.   local conffile
  429.  
  430.   # validate arguments
  431.   if [ $# -ne 1 ]; then
  432.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  433.                 "number of arguments; expected 1, got $#"
  434.     exit $SHELL_LIB_USAGE_ERROR
  435.   fi
  436.  
  437.   conffile="$1"
  438.  
  439.   remove_conffile_commit "$conffile"
  440. }
  441.  
  442. replace_conffile_with_symlink_rollback () {
  443.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  444.   #
  445.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  446.   # "newfilename".
  447.   #
  448.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  449.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  450.   # from a version (or install over a version removed-but-not-purged) prior
  451.   # to the one in which the conffile was obsoleted.
  452.   # You should have  used replace_conffile_with_symlink_prepare() in the
  453.   # preinst.
  454.  
  455.   local conffile
  456.  
  457.   # validate arguments
  458.   if [ $# -ne 2 ]; then
  459.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  460.                 "number of arguments; expected 2, got $#"
  461.     exit $SHELL_LIB_USAGE_ERROR
  462.   fi
  463.  
  464.   oldconffile="$1"
  465.   newconffile="$2"
  466.  
  467.   remove_conffile_rollback "$_oldconffile"
  468.   if [ -f "$newconffile" ]; then
  469.     rm "$newconffile"
  470.   fi
  471. }
  472.  
  473. run () {
  474.   # syntax: run command [ argument ... ]
  475.   #
  476.   # Run specified command with optional arguments and report its exit status.
  477.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  478.   # or commands whose failure is not fatal to us.
  479.   #
  480.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  481.   # those cases the return value of the debconf command *must* be checked
  482.   # before the string returned by debconf is used for anything.
  483.  
  484.   local retval
  485.  
  486.   # validate arguments
  487.   if [ $# -lt 1 ]; then
  488.     usage_error "run() called with wrong number of arguments; expected at" \
  489.                 "least 1, got $#"
  490.     exit $SHELL_LIB_USAGE_ERROR
  491.   fi
  492.  
  493.   "$@" || retval=$?
  494.  
  495.   if [ ${retval:-0} -ne 0 ]; then
  496.     observe "command \"$*\" exited with status $retval"
  497.   fi
  498. }
  499.  
  500. make_symlink_sane () {
  501.   # syntax: make_symlink_sane symlink target
  502.   #
  503.   # Ensure that the symbolic link symlink exists, and points to target.
  504.   #
  505.   # If symlink does not exist, create it and point it at target.
  506.   #
  507.   # If symlink exists but is not a symbolic link, back it up.
  508.   #
  509.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  510.   # it.
  511.   #
  512.   # If symlink exists, is a symbolic link, and already points to target, do
  513.   # nothing.
  514.   #
  515.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  516.  
  517.   # Validate arguments.
  518.   if [ $# -ne 2 ]; then
  519.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  520.       "expected 2, got $#"
  521.     exit $SHELL_LIB_USAGE_ERROR
  522.   fi
  523.  
  524.   # We could just use the positional parameters as-is, but that makes things
  525.   # harder to follow.
  526.   local symlink target
  527.  
  528.   symlink="$1"
  529.   target="$2"
  530.  
  531.   if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
  532.       observe "link from $symlink to $target already exists"
  533.   else
  534.     observe "creating symbolic link from $symlink to $target"
  535.     mkdir -p "${target%/*}" "${symlink%/*}"
  536.     ln -s -b -S ".dpkg-old" "$target" "$symlink"
  537.   fi
  538. }
  539.  
  540. migrate_dir_to_symlink () {
  541.   # syntax: migrate_dir_to_symlink old_location new_location
  542.   #
  543.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  544.   # symbolic link to a directory or vice versa; instead, the existing state
  545.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  546.   # there is one."
  547.   #
  548.   # We have to do it ourselves.
  549.   #
  550.   # This function moves the contents of old_location, a directory, into
  551.   # new_location, a directory, then makes old_location a symbolic link to
  552.   # new_location.
  553.   #
  554.   # old_location need not exist, but if it does, it must be a directory (or a
  555.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  556.   # exists already and is not a directory, it is backed up.
  557.   #
  558.   # This function should be called from a package's preinst so that other
  559.   # packages unpacked after this one --- but before this package's postinst runs
  560.   # --- are unpacked into new_location even if their payloads contain
  561.   # old_location filespecs.
  562.  
  563.   # Validate arguments.
  564.   if [ $# -ne 2 ]; then
  565.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  566.                 "arguments; expected 2, got $#"
  567.     exit $SHELL_LIB_USAGE_ERROR
  568.   fi
  569.  
  570.   # We could just use the positional parameters as-is, but that makes things
  571.   # harder to follow.
  572.   local new old
  573.  
  574.   old="$1"
  575.   new="$2"
  576.  
  577.   # Is old location a symlink?
  578.   if [ -L "$old" ]; then
  579.     # Does it already point to new location?
  580.     if [ "$(readlink "$old")" = "$new" ]; then
  581.       # Nothing to do; migration has already been done.
  582.       observe "migration of $old to $new already done"
  583.       return 0
  584.     else
  585.       # Back it up.
  586.       warn "backing up symbolic link $old as $old.dpkg-old"
  587.       mv -b "$old" "$old.dpkg-old"
  588.     fi
  589.   fi
  590.  
  591.   # Does old location exist, but is not a directory?
  592.   if [ -e "$old" ] && ! [ -d "$old" ]; then
  593.       # Back it up.
  594.       warn "backing up non-directory $old as $old.dpkg-old"
  595.       mv -b "$old" "$old.dpkg-old"
  596.   fi
  597.  
  598.   observe "migrating $old to $new"
  599.  
  600.   # Is new location a symlink?
  601.   if [ -L "$new" ]; then
  602.     # Does it point the wrong way, i.e., back to where we're migrating from?
  603.     if [ "$(readlink "$new")" = "$old" ]; then
  604.       # Get rid of it.
  605.       observe "removing symbolic link $new which points to $old"
  606.       rm "$new"
  607.     else
  608.       # Back it up.
  609.       warn "backing up symbolic link $new as $new.dpkg-old"
  610.       mv -b "$new" "$new.dpkg-old"
  611.     fi
  612.   fi
  613.  
  614.   # Does new location exist, but is not a directory?
  615.   if [ -e "$new" ] && ! [ -d "$new" ]; then
  616.     warn "backing up non-directory $new as $new.dpkg-old"
  617.     mv -b "$new" "$new.dpkg-old"
  618.   fi
  619.  
  620.   # Create new directory if it does not yet exist.
  621.   if ! [ -e "$new" ]; then
  622.     observe "creating $new"
  623.     mkdir -p "$new"
  624.   fi
  625.  
  626.   # Copy files in old location to new location.  Back up any filenames that
  627.   # already exist in the new location with the extension ".dpkg-old".
  628.   observe "copying files from $old to $new"
  629.   if ! (cd "$old" && cp -a -b -S ".dpkg-old" . "$new"); then
  630.     die "error(s) encountered while copying files from $old to $new"
  631.   fi
  632.  
  633.   # Remove files at old location.
  634.   observe "removing $old"
  635.   rm -r "$old"
  636.  
  637.   # Create symlink from old location to new location.
  638.   make_symlink_sane "$old" "$new"
  639. }
  640.  
  641. # vim:set ai et sw=2 ts=2 tw=80:
  642.  
  643. # GOBSTOPPER: The X Strike Force shell library ends here.
  644.  
  645. if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
  646.  
  647.   # create the configuration files' main and auxiliary directories if they
  648.   # don't exist
  649.   for DIR in "$CONFIG_DIR" "$CONFIG_AUX_DIR"; do
  650.     if ! [ -e "$DIR" ]; then
  651.       observe "creating $DIR"
  652.       mkdir --mode=755 --parents "$DIR"
  653.     fi
  654.   done
  655.  
  656.   # place config files under management if they do *not* already exist
  657.   if ! [ -e "$XWRAPPER_CONFIG" ]; then
  658.     touch "$XWRAPPER_CONFIG"
  659.     md5sum "$XWRAPPER_CONFIG" > "$XWRAPPER_CONFIG_CHECKSUM"
  660.   fi
  661. fi
  662.  
  663.  
  664.  
  665. exit 0
  666.  
  667. # vim:set ai et sts=2 sw=2 tw=0:
  668.